<template>
	<view class="whitePage">
		<!-- 搜索 -->
		<view class="flex pad20" style="background: #fff;">
			<u-search
				borderColor="#FE5E10"
				shape="round"
				bgColor="#fff"
				height="70rpx"
				placeholder="搜索关键词"
				:showAction="false"
				:inputStyle="{'padding-right': '95rpx'}"
				type="number"
				v-model="request.keyword"
			/>
			<view class="searchBtn" @click="search">搜索</view>
		</view>
		<!-- 列表数据 -->
		<view class="pad20">
			<view
				class="pad20 flex u-border-bottom"
				v-for="(item, index) in list"
				:key="index"
			>
				<u-avatar :src="item.avatar" size="110rpx" />
				<view class="info">
					<text>{{ item.nickName }}</text>
					<view>电话：{{ item.mobile || "未授权" }}</view>
					<view>UID：{{ item.userId || '' }}</view>
				</view>
				<view class="btn" @click="goRouter">运动处方</view>
			</view>
		</view>
		<!-- 空数据 -->
		<u-empty v-if="!list.length" mode="list" text="暂无数据..." />
	</view>
</template>

<script>
import { patientList, removeUser } from "@/api/doctor.js"
export default {
	data() {
		return {
			list: [],
			timer: null,
			totalPages: 1,
			request: {
				pageSize: 10,
				pageNum: 1,
				keyword: ''
			}
		}
	},
	onLoad(e) {
		this.request.sign = e.sign || ''
		this.getList()
	},
	onReachBottom() {
		this.timer && clearTimeout(this.timer);
		this.timer = setTimeout(() => this.getList(), 500);
	},
	methods: {
		// 页面跳转
		goRouter() {
			uni.navigateTo({
				url: '../prescription/list?type=doctor'
			})
		},
		/* 重置请求 */
		search() {
			this.request.pageNum = 1
			this.list = []
			this.totalPages = 1
			this.getList()
		},
		// 获取列表数据
		getList() {
			if(this.request.pageNum > this.totalPages) return
			patientList(this.request).then(res => {
				this.list = [...this.list, ...res.rows]
				this.totalPages = res.pages
				this.request.pageNum++
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.info {
	margin-left: 20rpx;
	flex: 1;
	text {
		font-size: 32rpx;
	}
	view {
		color: rgba(0, 0, 0, 0.6);
		font-size: 22rpx;
		margin-top: 10rpx;
	}
}
.btn {
	font-size: 24rpx;
	width: 120rpx;
	height: 45rpx;
	line-height: 45rpx;
	border-radius: 10rpx;
	background-color: #19be6b;
	color: #fff;
	text-align: center;
}
</style>
